package com.applet.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;

/**
 * @author “XuShao”
 * @date 2024/12/15 18:09
 * @description
 */
@Configuration
public class OpenApiConfig {

    @Value("${zyz.jwt.token-name}")
    private String tokenName;

    // OpenAPI类用于定制全局文档信息
    @Bean
    public OpenAPI customOpenAPI() {

        return new OpenAPI()

                // 定制文档基本信息
                .info(new Info()
                        //关于文档信息
                        .title("志愿者后端API")
                        .description("API志愿者后端API")
                        .version("1.0.0"))
                .components(new Components()
                        // 设置 spring security jwt accessToken 认证的请求头
                        .addSecuritySchemes("token", new SecurityScheme()
                                .type(SecurityScheme.Type.APIKEY)
                                .in(SecurityScheme.In.HEADER)
                                .name(tokenName)
                        ))
                .addSecurityItem(new SecurityRequirement().addList("token"))
                ;
    }

}
